﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyThuVien.Business;
using System.Windows.Forms;

namespace QuanLyThuVien.DataAccess
{
    class TheDAL
    {
        clsDatabase db = new clsDatabase();

        public void ThemMoiThe(TheThuVien the)
        {
            db.ThuThiSQL("insert into tbThe values(N'" + the.MaThe + "',N'" + the.MaDG + "',N'" + the.NgayCap + "',N'" + the.Han + "')");
        }

        public void SuaThe(TheThuVien the)
        {
            db.ThuThiSQL("update tbThe set MaDG=N'" + the.MaDG + "',NgayCap=N'" + the.NgayCap + "',Han=N'" + the.Han + "' where MaThe=N'" + the.MaThe + "'");
        }

        public void XoaThe(string MaThe)
        {
            db.ThuThiSQL("delete from tbThe where MaThe=N'" + MaThe + "'");
        }

        public void LoadLenDataGridView(DataGridView dg)
        {
            db.LoadLenDG(dg, "select tbThe.MaDG, TenDG, ChucVu,MaThe,NgayCap,Han from tbThe, tbDG where tbThe.MaDG=tbDG.MaDG");
        }

        public bool KiemTraMaThe(string MaThe)
        {
            return db.KiemTra("select count(*) from tbThe where MaThe=N'" + MaThe + "'");
        }

        public bool KiemTraMaDG(string MaDG)
        {
            return db.KiemTra("select count(*) from tbThe where MaDG=N'" + MaDG + "'");
        }

        public void LoadMaTheLenCB(ComboBox cb)
        {
            db.LoadLenCombobox(cb, "select MaThe from tbThe", 0);
        }

        public void XoaTheTheoMaDG(string maDG)
        {
            db.ThuThiSQL("delete from tbThe where MaDG=N'" + maDG + "'");
        }

    }
}
